package de.tum.in.eist.im.client;

import java.util.Date;
import java.util.List;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

import de.tum.in.eist.im.client.domain.Message;
import de.tum.in.eist.im.client.domain.NewMessagesChunk;
import de.tum.in.eist.im.client.domain.User;

/**
 * Interface for services that an EIST_IM server provides. The basic
 * functionality of the server requires only a subset of provided methods.
 * However for convenience and more flexibility in developing EIST_IM clients
 * different additional methods are provided. An implementation of ChatService
 * in provided in de.tum.in.eist.im.server.ChatServiceImpl class in
 * eist_im_server.jar.
 * 
 */
@RemoteServiceRelativePath("chatServiceNew")
public interface ChatServiceNew extends RemoteService {

    /**
     * Returns all messages that have been sent after the given timestamp.
     * Clients that are implemented by successive polling should use this
     * method. Every time that the client recive a NewMessageChunk it sets its
     * last time stamp to the time stamp of NewMessageChunk. The next time that
     * the client calls this method, it sends its last time stamp along.
     * 
     * @param lastTimestamp
     * @return an instance of NewMessageChunk that contains all messages that
     *         have arrived in the time between clientLastTimestamp and the time
     *         server receives the call. Note that the new messages are returned
     *         in the same order that they have arrived to the server
     */
    NewMessagesChunk getNewMessages(long clientLastTimestamp);

    /**
     * Sends a message to the server.
     * 
     * @param message
     */
    void sendMessage(Message message);

    /**
     * Logins a user. The user must be registered and can be authenticated by
     * the server.
     * 
     * @param user
     * @return true if user could be authenticated, otherwise false (user is not
     *         registered, or could not be authenticated).
     */
    boolean login(User user);

    /**
     * logs a user out.
     * 
     * @param user
     * @return true if user could be successfully logged out.
     */
    boolean logout(User user);

    /**
     * registeres a new user.
     * 
     * @param newUser
     */
    void registerNewUser(User newUser);

    /**
     * returns a list of users currently logged in to chat.
     * 
     * @return
     */
    List<User> getLoggedInUsers();

    /**
     * Returns all messages for the given date.
     * 
     * @param from
     * @return
     */
    List<Message> getHistory(Date from);
}
